package com.ljfirst.循环发令枪;

import lombok.SneakyThrows;

import java.util.concurrent.CyclicBarrier;

/**
 * @author liujun
 * @version 1.0
 * @date 2020/12/2
 * @author—Email liujunfirst@outlook.com
 * @blogURL https://blog.csdn.net/ljfirst
 * @description
 */
public class TaskThread extends Thread {

    CyclicBarrier barrier;

    public TaskThread(CyclicBarrier barrier) {
        this.barrier = barrier;
    }

    @SneakyThrows
    @Override
    public void run() {
        Thread.sleep(4_000);
        System.out.println(getName() + " 到达栅栏 A");
        barrier.await();
        System.out.println(getName() + " 冲破栅栏 A");

        Thread.sleep(4_000);
        System.out.println(getName() + " 到达栅栏 B");
        barrier.await();
        System.out.println(getName() + " 冲破栅栏 B");
    }
}
